package com.wdl.networkflow.uv

import org.apache.flink.streaming.api.windowing.triggers.{Trigger, TriggerResult}
import org.apache.flink.streaming.api.windowing.windows.TimeWindow

/**
 * 自定义一个触发器，每来一条数据，就触发一次窗口计算操作
 */
class MyTrigger() extends Trigger[(String, Long), TimeWindow]{

  /** 来一个元素触发 */
  override def onElement(element: (String, Long),
                         timestamp: Long,
                         window: TimeWindow,
                         ctx: Trigger.TriggerContext): TriggerResult = {
    /** 数据来了之后，触发计算并清空状态，不保存数据 */
    TriggerResult.FIRE_AND_PURGE
  }

  /** 系统处理时间触发 */
  override def onProcessingTime(time: Long,
                                window: TimeWindow,
                                ctx: Trigger.TriggerContext): TriggerResult = {
    TriggerResult.CONTINUE
  }

  /** water 来了以后触发 */
  override def onEventTime(time: Long,
                           window: TimeWindow,
                           ctx: Trigger.TriggerContext): TriggerResult = {
    TriggerResult.CONTINUE
  }

  /** 清空 */
  override def clear(window: TimeWindow, ctx: Trigger.TriggerContext): Unit = {

  }
}
